//
//  BaseCollectionView.m
//  Gift Show
//
//  Created by 史兴宇 on 16/3/23.
//  Copyright © 2016年 史兴宇. All rights reserved.
//

#import "BaseCollectionView.h"

@implementation BaseCollectionView


- (instancetype)initWithFrame:(CGRect)frame collectionViewLayout:(UICollectionViewLayout *)layout
{
    self = [super initWithFrame:frame collectionViewLayout:layout];
    if (self) {
        
        [self createCollections];
    }
    return self;
}
- (void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"night" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"day" object:nil];
    [super dealloc];
}
- (void)createCollections{
    
    
    self.bounces = NO; //关闭边缘反弹
//    self.scrollEnabled = YES;
    self.pagingEnabled = YES;

    
    
    
    
    BOOL result = [[NSUserDefaults standardUserDefaults] boolForKey:@"isNight"];
    
    if (result == YES) {
        
        self.backgroundColor = [UIColor colorWithWhite:0.200 alpha:1.000];

        
    }else{
        
        self.backgroundColor = [UIColor whiteColor];

    }
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nightAction:) name:@"night" object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(dayAction:) name:@"day" object:nil];
    
    
    
}
- (void)nightAction:(NSNotification *)notification {
    
    self.backgroundColor = [UIColor colorWithWhite:0.200 alpha:1.000];
    
    
    
}

- (void)dayAction:(NSNotification *)notification {
    
    NSLog(@"日间模式开启成功");
    
    self.backgroundColor = [UIColor whiteColor];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
